package com.ruoyi.kong.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.kong.entity.KongEntity;
import com.ruoyi.kong.entity.KongService;
import com.ruoyi.kong.entity.KongServiceResult;
import com.ruoyi.kong.service.IKongServiceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * kong 服务 控制类
 */
@RestController
@RequestMapping("/kong/service")
public class KongServiceConrtoller extends BaseController {

    @Autowired
    private IKongServiceInfoService kongProxyService;

    /**
     * 返回 所有kong 服务信息
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo getKongServiceInfos(){
        startPage();
        KongEntity<KongServiceResult> kongServiceList = kongProxyService.getKongServiceList();
        return getDataTable(kongServiceList.getData());
    }

    /**
     * 新增服务
     * @param kongService
     * @return
     */
    @PostMapping("/add")
    public AjaxResult addKongService(@RequestBody KongService kongService){
        KongEntity<KongService> kongServiceKongEntity = kongProxyService.addKongService(kongService);
        return AjaxResult.success(kongServiceKongEntity.getData());
    }


    /**
     * 删除服务
     * @param serviceId
     * @return
     */
    @DeleteMapping("/{serviceId}")
    public AjaxResult deleteKongService(@PathVariable  String serviceId){
        kongProxyService.deleteServices(serviceId);
        return success();
    }


    /**
     * 根据服务id 获取服务信息
     * @param serviceId
     * @return
     */
    @GetMapping("/{serviceId}")
    public AjaxResult getKongServiceById(@PathVariable  String serviceId){
        KongService kongService = kongProxyService.getKongServiceById(serviceId);
        return AjaxResult.success(kongService);
    }



    @PostMapping("/update/{id}")
    public AjaxResult updateKongService(@PathVariable String id,@RequestBody KongService kongService){
        KongEntity<KongService> kongServiceKongEntity = kongProxyService.updateServices(id, kongService);
        return AjaxResult.success(kongServiceKongEntity.getData());
    }










}
